// 导入 pinia
import { defineStore } from 'pinia'
// 导入 api
import { getHomeData } from '@/api/home'
// 创建pinia实例
export const useHomeStore = defineStore('homeStore', {
  state: () => ({
    homeListData: {}
  }),
  actions: {
    async getHomeListDat() {
      try {
        // 发送请求
        const result = await getHomeData()
        console.log(result)
        this.homeListData = result.data
      } catch (error) {
        console.log('请求失败', error)
      }
    }
  },
  getters: {
    // 通过计算属性来返回轮播图数据
    lunboList(state) {
      return state.homeListData.focusList
    },
    // 通过计算来返回口号nav渲染数据
    kouhaoList(state) {
      return state.homeListData?.policyDescList
    },
    // 类目导航数据
    kingkongList(state) {
      return state.homeListData?.kingKongModule?.kingKongList
    },
    // 类目热销榜数据
    categoryList(state) {
      return state.homeListData.categoryHotSellModule?.categoryList
    },

    // 临时清仓
    sceneLightShopping(state) {
      return state.homeListData.sceneLightShoppingGuideModule
    },
    // 新人导航礼
    indexActivityModule(state) {
      return state.homeListData.indexActivityModule
    }
  }
})
